//
//  OrderDetailsViewController.m
//  chongwu
//
//  Created by 隼目 on 2021/9/22.
//

#import "OrderDetailsViewController.h"
#import "OrderDetailsTableViewCell.h"
@interface OrderDetailsViewController ()<UITableViewDelegate,UITableViewDataSource,OrderDetailsDelegate>
@property(nonatomic,strong)BaseTableView *tableView;

@end

@implementation OrderDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title=@"订单详情";
    
    self.tableView=[BaseTableView new];
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(0);
        if (self.stateIndex==3) {
            make.bottom.mas_equalTo(-150*_mainHeight);
        }else{
            make.bottom.mas_equalTo(0);
        }
    }];
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.backgroundColor=rgba(245, 246, 246, 1);
    self.tableView.delegate=self;
    self.tableView.dataSource=self;
    if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    if (self.stateIndex==3) {
        [self creatBottomView];
    }
    
}
-(void)creatBottomView{
    UIView *bottomView=[UIView new];
    [self.view addSubview:bottomView];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(180*_mainHeight);
    }];
    bottomView.backgroundColor=[UIColor whiteColor];
    
    UIButton *submitBtn=[UIButton new];
    [bottomView addSubview:submitBtn];
    [submitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-30*_mainWidth);
        make.centerY.mas_equalTo(0);
        make.width.mas_equalTo(_mainWidth*301);
        make.height.mas_equalTo(86*_mainHeight);
    }];
    [submitBtn setTitle:@"不寄送了，申请退款" forState:0];
    [submitBtn setTitleColor:[UIColor whiteColor] forState:0];
    submitBtn.titleLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(28)];
    [submitBtn layoutIfNeeded];
    submitBtn.layer.masksToBounds=YES;
    submitBtn.layer.cornerRadius=86*_mainHeight/2;
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.frame = submitBtn.bounds;
    //将CAGradientlayer对象添加在我们要设置背景色的视图的layer层
    [submitBtn.layer insertSublayer:gradientLayer atIndex:0];
    //设置渐变区域的起始和终止位置（范围为0-1）
    gradientLayer.startPoint = CGPointMake(0, 1);
    gradientLayer.endPoint = CGPointMake(1, 1);
    gradientLayer.colors = @[(__bridge id)rgba(255,159,0,1).CGColor,
                             (__bridge id)rgba(255,116,0,1).CGColor ,
                             (__bridge id)rgba(255,102,0,1).CGColor];
    //设置颜色分割点（范围：0-1）
    gradientLayer.locations = @[@(0),@(0.5), @(1.0f)];
    submitBtn.layer.shadowColor = rgba(196,50,0,0.36).CGColor;
    submitBtn.layer.shadowOffset = CGSizeMake(0,0);
    submitBtn.layer.shadowOpacity = 0.5;
    submitBtn.layer.shadowRadius = 0.5;
//    [submitBtn addTarget:self action:@selector(selectPushToCashier) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    
    UILabel *titleLabel=[UILabel new];
    [bottomView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(47*_mainWidth);
        make.centerY.mas_equalTo(0);
        make.right.mas_equalTo(-361*_mainWidth);
    }];
    [titleLabel layoutIfNeeded];
    titleLabel.numberOfLines=0;
    titleLabel.text=@"揽件员王四海�]将在预约时间前上门取件，请您耐心等待，如有问题，可随时电话咨询～";
    titleLabel.textColor=rgba(153,153,153,1);
    titleLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(24)];
    
    UIView *quanView=[UIView new];
    [bottomView addSubview:quanView];
    [quanView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30*_mainWidth);
        make.top.mas_equalTo(titleLabel).mas_equalTo(13*_mainHeight);
        make.width.height.mas_equalTo(7*_mainWidth);
    }];
    quanView.layer.masksToBounds=YES;
    quanView.layer.cornerRadius=3.5*_mainWidth;
    quanView.layer.borderWidth=1*_mainWidth;
    quanView.layer.borderColor=rgba(250,100,0,1).CGColor;
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (self.stateIndex==2) {
        return 4;
    }
    return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    OrderDetailsTableViewCell *cell=[[OrderDetailsTableViewCell alloc]init];
    cell.delegate=self;
    if (indexPath.row==0) {
        [cell creatAddressView];
    }else if (indexPath.row==1) {
        if (self.stateIndex==0) {
            [cell creatCompletedView];
        }else if (self.stateIndex==1) {
            [cell creatSignedView];
        }else if (self.stateIndex==2) {
            [cell creatPaymentView];
        }else if (self.stateIndex==3) {
            [cell creatOutstandingPartsView];
        }else if (self.stateIndex==4) {
            [cell creatCancelView];
        }else if (self.stateIndex==5) {
            [cell creatInRefundView];
        }else if (self.stateIndex==6) {
            [cell creatRefundedView];
        }


    }else if (indexPath.row==2) {
        if (self.stateIndex==0) {
            [cell creatPetView];
        }if (self.stateIndex==1) {
            [cell creatPetView];
        }else if (self.stateIndex==2) {
            [cell creatPetView2];
        }else if (self.stateIndex==3) {
            [cell creatPetView2];
        }else if (self.stateIndex==4) {
            [cell creatPetView2];
        }else if (self.stateIndex==5) {
            [cell creatPetView2];
        }else if (self.stateIndex==6) {
            [cell creatPetView2];
        }
    }else if (indexPath.row==3) {
      if (self.stateIndex==2) {
            [cell creatPaymentBtnView];
        }
    }
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return  cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

   
    if (indexPath.row==0) {
        return 353*_mainHeight;
    }else if (indexPath.row==1) {
        if (self.stateIndex==0) {
            return 517*_mainHeight;
        }else if (self.stateIndex==1) {
            return 517*_mainHeight;
        }else if (self.stateIndex==2) {
            return 403*_mainHeight;
        }else if (self.stateIndex==3) {
            return 460*_mainHeight;
        }else if (self.stateIndex==4) {
            return 403*_mainHeight;
        }else if (self.stateIndex==5) {
            return 403*_mainHeight;
        }else if (self.stateIndex==6) {
            return 460*_mainHeight;
        }
        
    }else if (indexPath.row==2) {
        if (self.stateIndex==0) {
            return (42+36)*_mainHeight+286*2*_mainHeight+20*_mainHeight;
        }else if (self.stateIndex==1) {
            return (42+36)*_mainHeight+286*2*_mainHeight+20*_mainHeight;
        }else if (self.stateIndex==2) {
            return (42+36)*_mainHeight+207*2*_mainHeight+20*_mainHeight;
        }else if (self.stateIndex==3) {
            return (42+36)*_mainHeight+207*2*_mainHeight+20*_mainHeight;
        }else if (self.stateIndex==4) {
            return (42+36)*_mainHeight+207*2*_mainHeight+20*_mainHeight;
        }else if (self.stateIndex==5) {
            return (42+36)*_mainHeight+207*2*_mainHeight+20*_mainHeight;
        }else if (self.stateIndex==6) {
            return (42+36)*_mainHeight+207*2*_mainHeight+20*_mainHeight;
        }
    }else if (indexPath.row==3) {
        if (self.stateIndex==2) {
            return 454*_mainHeight;
        }
    }
    return 0;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
